package com.itwill.ecom.orders;

import java.sql.Date;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class OrdersServiceImpl implements OrdersService {

	@Autowired
	OrdersDao ordersDao;

	public OrdersServiceImpl() {
		
	}

	public OrdersDao getOrdersdao() {
		return ordersDao;
	}

	public void setOrdersDao(OrdersDao ordersdao) {
		this.ordersDao = ordersdao;
	}

	@Override
	public boolean createOrders(OrdersBeans ordersBeans) {
		boolean result = false;
		
		try{
			getOrdersdao().create(ordersBeans);
			result = true;
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		return result;
	}

	@Override
	public List<OrdersBeans> getOrdersByMemberNo(HashMap<String, String> pagemap) {
		List<OrdersBeans> resultList = null;
		
		try{
			resultList = getOrdersdao().readByMemberNo(pagemap);
		}
		catch(Exception e){
			System.out.println(e.getMessage());
			e.printStackTrace();
		}
		
		return resultList;
	}
	
	@Override
	public OrdersBeans getOrdersByOrdersNo(int orders_no) {
		OrdersBeans resultBean = null;
		
		try{
			resultBean = getOrdersdao().readByOrdersNo(orders_no);
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		return resultBean;
	}
	
	@Override
	public int getMaxOrdersNo(int memberNo){
		int result = 0;
		
		try{
			result = getOrdersdao().readMaxOrdersNo(memberNo);
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		return result;
	}
	
	@Override
	public int getOrdersCount(int memberNo) {
		int result = 0;
		
		try{
			result = getOrdersdao().readCount(memberNo);
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		return result;
	}

	@Override
	public boolean deleteOrders(int orders_no) {
		boolean result = false;
		
		try{
			getOrdersdao().delete(orders_no);
			result = true;
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		return result;
	}

}
